<?php
require './model/Db.php';
$Db = Db::getInstance();
$user_data = $Db->islogin();
$isMobile = preg_match('/mobile/i', $_SERVER['HTTP_USER_AGENT']);
$zone_data = $Db->find([
	table => ['zone'],
	where => "1 order by sort,id"
]);
//全站热门数据
$webhot = $Db->find([
	table => [content => 'a',module => 'b'],
	field => 'a.*,b.id mid,b.name',
	where => "a.mid = b.id and a.cid = 0 and a.delete_time is NULL order by a.look_num desc limit 0,5"
]);
$webhot = $Db->tohtml($webhot);
//校园热点数据
$schoolhot = $Db->find([
	table => [content => 'a',module => 'b'],
	field => 'a.*',
	where => "a.mid = b.id and b.name = '校园热点' and a.delete_time is NULL order by time limit 0,5"
]);
$schoolhot = $Db->tohtml($schoolhot);
//失物招领数据
$lost = $Db->find([
	table => [content => 'a',module => 'b'],
	field => 'a.*',
	where => "a.mid = b.id and b.name = '失物招领' and a.delete_time is NULL order by time limit 0,5"
]);
$lost = $Db->tohtml($lost);
//热门版面数据
$banhot = $Db->find([
	table => [content => 'a',module => 'b'],
	field => 'count(*) cnt,b.id,b.name,b.info',
	where => "a.mid=b.id GROUP BY b.id order by cnt desc,b.collect_num desc limit 0,10"
]);
$banhot = $Db->tohtml($banhot);
//版面列表数据
$data_arr = [];
foreach ($zone_data as $item) {
	$module_data = $Db->find([
		table => [zone => 'a',module => 'b'],
		field => 'b.*',
		where => "a.id = b.zid and a.id = {$item['id']}"
	]);
	$item['module'] = $module_data;
	$mids = '';
	foreach ($module_data as $m_item) {
		$mids .= $m_item['id'].',';
	}
	$mids = trim($mids,',');
	if(!$mids){
		$mids = -1;
	}
	$content_data = $Db->find([
		table => [content => 'a',module => 'b'],
		field => "a.*,b.id mid,b.name",
		where => "a.mid = b.id and a.cid = 0 and a.mid in ({$mids}) and a.delete_time is NULL order by a.time limit 0,5"
	]);
	$item['content'] = $content_data;
	$data_arr[] = $item;
}
$data_arr = $Db->tohtml($data_arr);
$web_title = '首页';
$css = [
	'public/css/my-bootstrap.min.css',
	'public/css/home.all.min.css'
];
include './view/header.html';
include './view/home.all.html';
include './view/footer.html';
$Db->close();